import axios from "axios";
// 创建axios实例
const service = axios.create({});
// request拦截器
service.interceptors.request.use(
  config => {
    config.headers["tokenid"] = "435065970"; // 请求头中添加tokenid
    return config;
  },
  error => {
    Promise.reject(error);
  }
);
// response拦截器
service.interceptors.response.use(
  response => {
    if (response) {
      return response.data;
    } else {
      Promise.reject(new Error("error"));
    }
  },
  error => {
    if (JSON.stringify(error).includes("401")) {
      alert("登录已过期，请重新登录！");
    } else {
      alert(error);
    }
    return Promise.reject(error);
  }
);
export default service;